#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int a[100010];

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int k, n; cin >> k;
    vector<int> v;
    for (int i = 0; i < k; i++) {
        int x; cin >> x;
        v.push_back(x);
        while (x != 1) {
            if (x & 1) x = x * 3 + 1;
            x /= 2;
            if (a[x] == 1) break;
            a[x] = 1;
        }
    }
    sort(v.begin(), v.end(), greater<int>());
    int cnt = 0;
    for (int i = 0; i < v.size(); i++) {
        if (a[v[i]] == 0) {
            cnt++;
            if (cnt == 1) cout << v[i];
            else cout << " " << v[i];
        }
    }
    return 0;
}